/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.QuestionnaireReply;
import com.boxin.ims.modules.wechat.dao.QuestionnaireReplyDao;

/**
 * 调查问卷回答Service
 * @author XiaoQian
 * @version 2014-05-09
 */
@Component
@Transactional(readOnly = true)
public class QuestionnaireReplyService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(QuestionnaireReplyService.class);
	
	@Autowired
	private QuestionnaireReplyDao questionnaireReplyDao;
	
	public QuestionnaireReply get(Long id) {
		return questionnaireReplyDao.findOne(id);
	}
	
	public Page<QuestionnaireReply> find(Page<QuestionnaireReply> page, QuestionnaireReply questionnaireReply) {
		DetachedCriteria dc = questionnaireReplyDao.createDetachedCriteria();
		dc.addOrder(Order.desc("id"));
		return questionnaireReplyDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(QuestionnaireReply questionnaireReply) {
		questionnaireReplyDao.save(questionnaireReply);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		questionnaireReplyDao.deleteById(id);
	}
	
	
	public List<QuestionnaireReply> findByReplyHumanId(Long replyHumanId ) {
		DetachedCriteria dc = questionnaireReplyDao.createDetachedCriteria();
		dc.createAlias("replyHuman", "replyHuman");
		dc.add(Restrictions.eq("replyHuman.id", replyHumanId));
		dc.addOrder(Order.desc("id"));
		return questionnaireReplyDao.find( dc);
	}
	
}
